package com.vend.common.base.agent;

import com.just.agentweb.MiddlewareWebClientBase;
import com.vend.common.base.sonic.SonicImpl;


/**
 * Created by glendal on 2022/01/18.
 */
public abstract class AgentFastWebFragment  extends  AgentWebFragment{
    private SonicImpl mSonicImpl;

    @Override
    public int getContentViewId() {
        return 0;
    }

    @Override
    public void lazyInit() {
        // 1. 首先创建SonicImpl
        mSonicImpl = new SonicImpl(getSnoicUrl(), this.getContext());
        // 2. 调用 onCreateSession
        mSonicImpl.onCreateSession();
        //3. 创建AgentWeb ，注意创建AgentWeb的时候应该使用加入SonicWebViewClient中间件
        super.lazyInit();
        //4. 注入 JavaScriptInterface
//        mAgentWeb.getJsInterfaceHolder().addJavaObject("sonic", new SonicJavaScriptInterface(mSonicImpl.getSonicSessionClient(), new Intent().putExtra(PARAM_CLICK_TIME,getArguments().getLong(PARAM_CLICK_TIME)).putExtra("loadUrlTime", System.currentTimeMillis())));
        //5. 最后绑定AgentWeb
        mSonicImpl.bindAgentWeb(mAgentWeb);

    }

    //在步骤3的时候应该传入给AgentWeb
    @Override
    public MiddlewareWebClientBase getMiddlewareWebClient() {
        return mSonicImpl.createSonicClientMiddleWare();
    }
    public String getSnoicUrl(){
        return "";
    };
    //getUrl 应该为null
    @Override
    public String getUrl() {
        return null;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        //销毁SonicSession
        if(mSonicImpl !=null){
            mSonicImpl.destrory();
        }
    }
}
